package xhwl.android.pay;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import xhwl.android.pay.bean.PayBean;
import xhwl.android.pay.invoke.PayManager;
public class MainActivity extends Activity {
	EditText orderNoEdit,moneyEdit,typeEdit;
	Button submitBtn;
	String orderNo,money,type;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		orderNoEdit=(EditText) findViewById(R.id.orderno_edit);
		moneyEdit=(EditText) findViewById(R.id.money_edit);
		typeEdit=(EditText) findViewById(R.id.type_edit);
		submitBtn=(Button) findViewById(R.id.submit_btn);
		submitBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(vilidInput()){
					PayBean payBean=new PayBean(orderNo,"测试服务",money);
					PayManager.getInstance().startPayment(MainActivity.this,payBean);
				}
				else
				{
					Toast.makeText(MainActivity.this, "输入有误", Toast.LENGTH_SHORT).show();
				}
			}
		});
	}
	protected boolean vilidInput() {
		// TODO Auto-generated method stub
		orderNo=orderNoEdit.getText().toString();
		money=moneyEdit.getText().toString();
		type=typeEdit.getText().toString();
		
		if(orderNo.length()>0&&money.length()>0&&type.length()>0){
			double m=Double.parseDouble(money);
			int t=Integer.parseInt(type);
			if(m>0&&(t==0||t==1))
				return true;
		}
		return false;
	}


}
